package weixinkeji.dev.dc.buy.order.h.fwy;

import com.alibaba.fastjson.JSON;
import sys.wx.ann.hm.M;
import sys.wx.ann.power.head.SQ;
import sys.wx.c.ATR;
import sys.wx.c.components.check.bean.CheckData;
import sys.wx.c.components.cv.CV;
import sys.wx.m.db.dao.mysql.Dao;
import sys.wx.xy.XY;
import weixinkeji.dev.dc.DCPower;
import weixinkeji.dev.dc.base.user.bean.FWY;
import weixinkeji.dev.dc.buy.order.bean.FWYOrder;
import weixinkeji.dev.dc.buy.order.so.FWYOrderSO;
import weixinkeji.dev.dc.buy.order.xy.FWYOrderXY;

@sys.wx.ann.hm.H("view/buy/order/fwy/kd")

//身份类型授权。无需人工付权。
//代表 是服务员才能进行访问。
//缓存用户选择操作的单据
@SQ(DCPower.ID_FWY)
public class FWYKDH_SelectFWYOrder {

    //设置当前操作订单。
    @M("/set/order")//通过 view/buy/order/fwy/kd/set/order.imy 访问
    public static String setOrder(ATR a) {
        String id = CV.getParameter(a.request, "order_id", CheckData.ID);
        if (null == id) {
            return null;
        }
        a.session.setAttribute(FWYOrderXY.H_MYSELECT_ORDER, id);
        a.out_OK_NO(true);
        return null;
    }

    //查询当前选择操作的订单
    @M("/select/order")//通过 view/buy/order/fwy/kd/select/order.imy 访问
    public static String selectOrder(ATR a) {
        Object id = a.session.getAttribute(FWYOrderXY.H_MYSELECT_ORDER);
        if (null == id) {
            a.printOne("{}");
            return null;
        }
        a.printOne(
                JSON.toJSONStringWithDateFormat(
                        Dao.selectOneByID(FWYOrder.class, id.toString()), XY.TIME_FORMAT)
        );
        return null;
    }

    //开单界面查询明细
    @M("/select/orderb/list")//通过 view/buy/order/fwy/kd/select/orderb/list.imy 访问
    public static String selectOne(ATR a) {

        //取出要操作的订单表头ID
        String order_id = CV.getParameter(a.request, "order_id", CheckData.ID);
        if (null == order_id) {
            return null;
        }
        String account = ((FWY) a.session.getAttribute(XY.SESSION_LOGIN)).getFwy_account();
        a.printOne(JSON.toJSONString(FWYOrderSO.selectOneFWYOrderB_FWY(order_id, account)));
        return null;
    }
  //开单界面查询明细
    @M("/select/order/one")//通过 view/buy/order/fwy/kd/select/order/one.imy 访问
    public static String selectDBOne(ATR a) {

        //取出要操作的订单表头ID
        String order_id = CV.getParameter(a.request, "order_id", CheckData.ID);
        if (null == order_id) {
            return null;
        }
           a.printOne(
                JSON.toJSONStringWithDateFormat(
                        Dao.selectOneByID(FWYOrder.class, order_id), XY.TIME_FORMAT)
        );
        return null;
    }
}
